<?php
	define('SSLIB_Group', TRUE);
	define('sslib_groups_compiled'	, 'sslibgroupscompiled'	);
	define('sslib_groups_names'		, 'sslibgroupsnames'	);
	class Group
	{
		static function Init()
		{
			$file = Sslib::Variable('site.private.path').'sslib_groups.inc';
			if(!file_exists($file))	Group::CompileCache();
			
			include($file);
			
			//or	new Err(_T('file not found').Sslib::Variable('site.private.path').'sslib_groups.inc');
		}
		static function CompileCache()
		{
			$data = Sslib::DB()->Query('SELECT * FROM '.Sql::Quote(Sslib::TableGroups(),false));
			$arr = array();
			$arr1 = array();
			$res='<'.'? $_ENV[\''.sslib_groups_compiled.'\'] = array(';
			$res1='$_ENV[\''.sslib_groups_names.'\'] = array(';
			while($row = $data->Row())
			{
				$arr[] = $row['id'].'=>array('.'\''.Text::Lower($row['name']).'\','.$row['parent'].','.'\''.$row['descrip'].'\')';
				$arr1[] = '\''.$row['name'].'\''.'=>'.$row['id'];
			}
			$res .= implode(',', $arr).");\n";
			$res1 .= implode(',', $arr1).'); ?'.'>';
			$f = fopen(Sslib::Variable('site.private.path').'sslib_groups.inc', 'w+');
			fwrite($f, $res.$res1);
			fclose($f);
		}
		static function ToInt($groupname)
		{
			if(!array_key_exists($groupname, $_ENV[sslib_groups_names]))
				die(__T('missing group name').": $groupname");
			else 
				return $_ENV[sslib_groups_names][$groupname];
		
		}
		
	}
?>